/*
 * Copyright (C) 2010-2011 Graz University of Technology, Austria. All Rights reserved. 
 *
 * Contact: Simone Kopeinik <simone.kopeinik@tugraz.at>
 * 	   Graz University of Technology, Knowledge Management Institute, Brückenkopfgasse 1/6, 8020 Graz 	
 * 	   <http://www.kmi.tugraz.at/>
 * 
 * This software is part of the TARGET platform developed by the
 * TARGET EC-funded project www.reachyourtarget.org
 *
 * This software is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, version 3.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * The GNU General Public License is available at <http://www.gnu.org/licenses/>.
 *
 */
package at.tugraz.kmi.css.cbkst2;

import com.google.common.collect.HashMultimap;
import com.google.common.collect.ImmutableCollection;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Multimap;
import com.google.common.collect.Multimaps;

/**
 * The CbKSTPerformance Function is the inverse of the CbKSTCompetence Function.
 * 
 * @author Georg Öttl <georg.oettl@gmail.com>
 * 
 */
class PerformanceFunction implements
		TransferFunction<CbKSTPerformance, CbKSTCompetence> {

	private Multimap<CbKSTPerformance, CbKSTCompetence>	graphMapping;

	/**
	 * Default constructor creates empty problem mapping.
	 */
	public PerformanceFunction() {
		this(null);
	}

	PerformanceFunction(Multimap<CbKSTPerformance, CbKSTCompetence> graphMapping) {
		if (graphMapping == null) {
			this.graphMapping = HashMultimap.create();
		} else {
			this.graphMapping = graphMapping;
		}
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void addMapping(CbKSTPerformance problem, CbKSTCompetence... skill) {
		graphMapping.putAll(problem, ImmutableSet.copyOf(skill));

	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public CompetenceFunction invert() {
		Multimap<CbKSTCompetence, CbKSTPerformance> problemMapping = HashMultimap
				.create();
		Multimaps.invertFrom(graphMapping, problemMapping);
		return new CompetenceFunction(problemMapping);
	}

	@Override
	public ImmutableCollection<CbKSTCompetence> get(CbKSTPerformance key) {
		return ImmutableList.copyOf(graphMapping.get(key));
	}

}
